//
//  Rae_ex_view.swift
//  77Club
//
//  Created by Apple on 2024/8/28.
//

import Foundation

extension UIView {
    @objc func addCorner(conrners: UIRectCorner , radius: CGFloat) {
        
//        let maskPath = UIBezierPath(roundedRect: self.bounds, byRoundingCorners: conrners, cornerRadii: CGSize(width: radius, height: radius))
//        let maskLayer = CAShapeLayer()
//        maskLayer.frame = self.bounds
//        maskLayer.path = maskPath.cgPath
//        self.layer.mask = maskLayer
        var cornerMask = CACornerMask()
        if conrners.contains(.topLeft) {
            cornerMask.insert(.layerMinXMinYCorner)
        }
        if conrners.contains(.topRight) {
            cornerMask.insert(.layerMaxXMinYCorner)
        }
        if conrners.contains(.bottomLeft) {
            cornerMask.insert(.layerMinXMaxYCorner)
        }
        if conrners.contains(.bottomRight) {
            cornerMask.insert(.layerMaxXMaxYCorner)
        }
        self.rae.corner(radius, corners: cornerMask)
    }
    
    func addCornerAndBorder(conrners: UIRectCorner , radius: CGFloat, borderWidth:CGFloat,borderColor:UIColor) {
        
        let maskLayer = CAShapeLayer()
        maskLayer.frame = self.bounds
        maskLayer.path = UIBezierPath(roundedRect: self.bounds, byRoundingCorners: conrners, cornerRadii: CGSize(width: radius, height: radius)).cgPath
        self.layer.mask = maskLayer
        // Add border
        let borderLayer = CAShapeLayer()
        borderLayer.path = maskLayer.path // Reuse the Bezier path
        borderLayer.fillColor = UIColor.clear.cgColor
        borderLayer.strokeColor = borderColor.cgColor
        borderLayer.lineWidth = borderWidth
        borderLayer.frame = self.bounds
        self.layer.addSublayer(borderLayer)
    }
}
